<template>
  <el-dropdown trigger="click" @command="handleSetLang">
    <div class="lang-select">
      <el-icon :size="18">
        <Menu />
      </el-icon>
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item 
          v-for="item in langOptions"
          :key="item.key"
          :disabled="language === item.key"
          :command="item.key"
        >
          <span style="padding-right: 6px;">{{ item.icon }}</span>
          {{ item.title }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ElMessage } from 'element-plus'
import { Menu } from '@element-plus/icons-vue'
import { useAppStore } from '@/stores/app'

const appStore = useAppStore()

// 语言选项
const langOptions = [
  { key: 'zh-CN', title: '中文', icon: '🇨🇳' },
  { key: 'en-US', title: 'English', icon: '🇺🇸' }
]

// 当前语言
const language = computed(() => appStore.language)

// 处理语言设置
const handleSetLang = (lang: string) => {
  appStore.setLanguage(lang)
  const langOption = langOptions.find(item => item.key === lang)
  ElMessage.success(`语言切换成功: ${langOption?.title}`)
  
  // 这里可以添加国际化逻辑
  // 例如：i18n.global.locale = lang
}
</script>

<style scoped></style>
